const fs = require('fs');
const path = require('path');

// 创建目录函数
function ensureDirectoryExists(filePath) {
  const dirname = path.dirname(filePath);
  if (fs.existsSync(dirname)) {
    return true;
  }
  ensureDirectoryExists(dirname);
  fs.mkdirSync(dirname);
}

// 图标定义
const icons = {
  // TabBar 图标
  'home.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M3 9L12 2L21 9V20C21 20.5304 20.7893 21.0391 20.4142 21.4142C20.0391 21.7893 19.5304 22 19 22H5C4.46957 22 3.96086 21.7893 3.58579 21.4142C3.21071 21.0391 3 20.5304 3 20V9Z" stroke="#999999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    <path d="M9 22V12H15V22" stroke="#999999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`,

  'home_selected.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M3 9L12 2L21 9V20C21 20.5304 20.7893 21.0391 20.4142 21.4142C20.0391 21.7893 19.5304 22 19 22H5C4.46957 22 3.96086 21.7893 3.58579 21.4142C3.21071 21.0391 3 20.5304 3 20V9Z" stroke="#1296db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="#E6F4FB"/>
    <path d="M9 22V12H15V22" stroke="#1296db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`,

  'mall.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M20 6H4L5 20H19L20 6Z" stroke="#999999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    <path d="M8 6V4C8 3.46957 8.21071 2.96086 8.58579 2.58579C8.96086 2.21071 9.46957 2 10 2H14C14.5304 2 15.0391 2.21071 15.4142 2.58579C15.7893 2.96086 16 3.46957 16 4V6" stroke="#999999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    <path d="M9 10H10M15 10H14" stroke="#999999" stroke-width="2" stroke-linecap="round"/>
  </svg>`,

  'mall_selected.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M20 6H4L5 20H19L20 6Z" stroke="#1296db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="#E6F4FB"/>
    <path d="M8 6V4C8 3.46957 8.21071 2.96086 8.58579 2.58579C8.96086 2.21071 9.46957 2 10 2H14C14.5304 2 15.0391 2.21071 15.4142 2.58579C15.7893 2.96086 16 3.46957 16 4V6" stroke="#1296db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    <path d="M9 10H10M15 10H14" stroke="#1296db" stroke-width="2" stroke-linecap="round"/>
  </svg>`,

  'school.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M12 1L2 6L12 11L22 6L12 1Z" stroke="#999999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    <path d="M2 6V12" stroke="#999999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    <path d="M5 9V18C5 18 8 20 12 20C16 20 19 18 19 18V9" stroke="#999999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`,

  'school_selected.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M12 1L2 6L12 11L22 6L12 1Z" stroke="#1296db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="#E6F4FB"/>
    <path d="M2 6V12" stroke="#1296db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    <path d="M5 9V18C5 18 8 20 12 20C16 20 19 18 19 18V9" stroke="#1296db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`,

  'user.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M12 11C14.2091 11 16 9.20914 16 7C16 4.79086 14.2091 3 12 3C9.79086 3 8 4.79086 8 7C8 9.20914 9.79086 11 12 11Z" stroke="#999999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    <path d="M12 14C7.58172 14 4 17.5817 4 22H20C20 17.5817 16.4183 14 12 14Z" stroke="#999999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`,

  'user_selected.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M12 11C14.2091 11 16 9.20914 16 7C16 4.79086 14.2091 3 12 3C9.79086 3 8 4.79086 8 7C8 9.20914 9.79086 11 12 11Z" stroke="#1296db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="#E6F4FB"/>
    <path d="M12 14C7.58172 14 4 17.5817 4 22H20C20 17.5817 16.4183 14 12 14Z" stroke="#1296db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="#E6F4FB"/>
  </svg>`,

  // 功能图标
  'default_avatar.svg': `<svg viewBox="0 0 200 200" fill="none" xmlns="http://www.w3.org/2000/svg">
    <circle cx="100" cy="100" r="95" fill="#E0E0E0" stroke="#CCCCCC" stroke-width="2"/>
    <circle cx="100" cy="80" r="30" fill="#ADADAD"/>
    <path d="M100 120C77.9086 120 60 137.909 60 160H140C140 137.909 122.091 120 100 120Z" fill="#ADADAD"/>
  </svg>`,

  'share.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <circle cx="17" cy="5" r="3" stroke="#1296db" stroke-width="2"/>
    <circle cx="5" cy="12" r="3" stroke="#1296db" stroke-width="2"/>
    <circle cx="17" cy="19" r="3" stroke="#1296db" stroke-width="2"/>
    <path d="M8 10.5L14 7.5M8 13.5L14 16.5" stroke="#1296db" stroke-width="2"/>
  </svg>`,

  'certificate.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <rect x="3" y="2" width="18" height="20" rx="2" stroke="#1296db" stroke-width="2" fill="#E6F4FB"/>
    <path d="M8 7H16M8 12H16M8 17H13" stroke="#1296db" stroke-width="2" stroke-linecap="round"/>
  </svg>`,

  // 登录页面图标
  'logo.svg': `<svg viewBox="0 0 200 200" fill="none" xmlns="http://www.w3.org/2000/svg">
    <circle cx="100" cy="100" r="95" fill="#E6F4FB" stroke="#1296db" stroke-width="5"/>
    <path d="M100 50C83.4315 50 70 63.4315 70 80C70 96.5685 83.4315 110 100 110C116.569 110 130 96.5685 130 80C130 63.4315 116.569 50 100 50Z" fill="#1296db"/>
    <path d="M160 150C160 128.909 137.6 112 110 112H90C62.4 112 40 128.909 40 150H160Z" fill="#1296db"/>
  </svg>`,

  'wechat.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M9.5 8C8.67157 8 8 8.67157 8 9.5C8 10.3284 8.67157 11 9.5 11C10.3284 11 11 10.3284 11 9.5C11 8.67157 10.3284 8 9.5 8Z" fill="white"/>
    <path d="M14.5 8C13.6716 8 13 8.67157 13 9.5C13 10.3284 13.6716 11 14.5 11C15.3284 11 16 10.3284 16 9.5C16 8.67157 15.3284 8 14.5 8Z" fill="white"/>
    <path d="M16.5 14C15.6716 14 15 14.6716 15 15.5C15 16.3284 15.6716 17 16.5 17C17.3284 17 18 16.3284 18 15.5C18 14.6716 17.3284 14 16.5 14Z" fill="white"/>
    <path d="M9.5 14C8.67157 14 8 14.6716 8 15.5C8 16.3284 8.67157 17 9.5 17C10.3284 17 11 16.3284 11 15.5C11 14.6716 10.3284 14 9.5 14Z" fill="white"/>
    <path fill-rule="evenodd" clip-rule="evenodd" d="M12 4C7.58172 4 4 7.13401 4 11C4 12.8695 4.91142 14.5555 6.36877 15.7627C6.64322 15.9946 6.7881 16.3348 6.75778 16.6825L6.60416 18.0432C6.54992 18.6967 7.19648 19.1935 7.8134 18.9555L9.64499 18.2383C9.9143 18.1329 10.206 18.1187 10.4839 18.1972C10.9671 18.3242 11.4739 18.3913 12 18.3913C12.2688 18.3913 12.5333 18.3742 12.7919 18.3411C13.1102 18.3024 13.4244 18.4941 13.5415 18.8006C14.5549 21.3066 17.0903 23 20 23C20.516 23 21.0132 22.9342 21.4873 22.8096C21.7595 22.7352 22.0442 22.7499 22.3082 22.8515L24.1678 23.5597C24.7847 23.7976 25.4313 23.3008 25.377 22.6474L25.2234 21.2866C25.1931 20.9389 25.338 20.5987 25.6124 20.3669C27.0698 19.1597 27.9812 17.4736 27.9812 15.6041C27.9812 11.7381 24.3995 8.6041 19.9812 8.6041C19.8532 8.6041 19.7262 8.60798 19.6004 8.61558C19.1752 5.87504 15.9348 4 12 4Z" fill="white"/>
  </svg>`,

  'phone.svg': `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M15.05 5C16.0267 5.19057 16.9244 5.66826 17.6281 6.37194C18.3317 7.07561 18.8094 7.97326 19 8.95M15.05 1C17.0793 1.22544 18.9716 2.13417 20.4162 3.57701C21.8609 5.01984 22.7721 6.91101 23 8.94M22 16.92V19.92C22.0011 20.1985 21.9441 20.4742 21.8325 20.7293C21.7209 20.9845 21.5573 21.2136 21.3521 21.4019C21.1468 21.5901 20.9046 21.7335 20.6407 21.8227C20.3769 21.9119 20.0974 21.9451 19.82 21.92C16.7428 21.5856 13.787 20.5341 11.19 18.85C8.77383 17.3147 6.72534 15.2662 5.19 12.85C3.49998 10.2412 2.44824 7.27099 2.12 4.18C2.09501 3.90347 2.12788 3.62476 2.21649 3.36162C2.30511 3.09849 2.44756 2.85669 2.63476 2.65162C2.82196 2.44655 3.0498 2.28271 3.30379 2.17052C3.55777 2.05833 3.83233 2.00026 4.11 2H7.11C7.59531 1.99522 8.06579 2.16708 8.43376 2.48353C8.80173 2.79999 9.04208 3.23945 9.11 3.72C9.23662 4.68007 9.47145 5.62273 9.81 6.53C9.9446 6.88792 9.97372 7.27691 9.89396 7.65088C9.8142 8.02485 9.62886 8.36811 9.36 8.64L8.09 9.91C9.51354 12.4135 11.5865 14.4865 14.09 15.91L15.36 14.64C15.6319 14.3711 15.9752 14.1858 16.3491 14.106C16.7231 14.0263 17.1121 14.0554 17.47 14.19C18.3773 14.5286 19.3199 14.7634 20.28 14.89C20.7658 14.9585 21.2094 15.2032 21.5265 15.5775C21.8437 15.9518 22.0122 16.4296 22 16.92Z" stroke="#1296db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`
};

// 同时创建PNG版本的图标信息
const pngIcons = {
  'home.png': icons['home.svg'],
  'home_selected.png': icons['home_selected.svg'],
  'mall.png': icons['mall.svg'],
  'mall_selected.png': icons['mall_selected.svg'],
  'school.png': icons['school.svg'],
  'school_selected.png': icons['school_selected.svg'],
  'user.png': icons['user.svg'],
  'user_selected.png': icons['user_selected.svg'],
  'default_avatar.png': icons['default_avatar.svg'],
  'share.png': icons['share.svg'],
  'certificate.png': icons['certificate.svg'],
  'logo.png': icons['logo.svg'],
  'wechat.png': icons['wechat.svg'],
  'phone.png': icons['phone.svg']
};

// 生成所有图标
console.log('开始生成图标文件...');

// 先创建SVG版本
Object.entries(icons).forEach(([filename, svgContent]) => {
  const filePath = path.join(__dirname, filename);
  ensureDirectoryExists(filePath);
  fs.writeFileSync(filePath, svgContent);
  console.log(`已创建SVG图标: ${filename}`);
});

// 创建PNG版本（虽然内容是SVG，但文件名使用PNG扩展名，以满足项目需求）
Object.entries(pngIcons).forEach(([filename, svgContent]) => {
  const filePath = path.join(__dirname, filename);
  ensureDirectoryExists(filePath);
  fs.writeFileSync(filePath, svgContent);
  console.log(`已创建PNG命名的图标文件（SVG内容）: ${filename}`);
});

console.log('所有图标文件已成功生成！'); 